<template>
  <view class="hpu_item_block">
    <view class="network">
      <view class="left">
        <image src="../../assets/images/codeList/network_house.png"></image>
        <text>{{ props.item.companyName }}网点</text>
      </view>
      <view class="right">
        <image src="../../assets/images/codeList/phone.png" @touchStart="toDial(props.item.tel)"></image>
        <image src="../../assets/images/codeList/marker.png" style="margin-left: 32rpx" @touchStart="toMap(props.item)"></image>
      </view>
    </view>
    <view class="codes" v-for="(item,index) in props.item.orderList">
      <view class="order">
        <view class="order_text">
          <text>承运单号：{{ item.billNo }}</text>
          <image src="../../assets/images/codeList/paper.png" @tap="copyCode(item.billNo)"></image>
        </view>
        <view class="order_detail" @click="toOrderDetail(item.billNo)">运单详情＞</view>
      </view>
      <view class="addr">
        <view class="title_1">发</view>
        <view class="name">{{ item.shipper }}</view>
        <view class="pos">{{ item.toProvince }}&nbsp;{{ item.toFromCity }}</view>
      </view>
      <view class="addr">
        <view class="title_2">收</view>
        <view class="name">{{ item.receiver }}</view>
        <view class="pos">{{ item.fromProvince }}&nbsp;{{ item.fromCity }}</view>
      </view>
      <view class="goods">
        货物信息：{{goodsInfoString(item)}}
      </view>
    </view>

    <dialBranch :show="showTelPopup" :tel="branchTel" :title="'拨打电话'" @close="showTelPopup=false" :show-close="true"></dialBranch>
  </view>
</template>

<script setup lang="ts">
import Taro from "@tarojs/taro"
import { ref, defineProps, defineEmits } from 'vue'
import { IconFont } from '@nutui/icons-vue-taro';
import {$get,$post} from "@/@api";
import useMyOrderStore from "@/store/myOrder";
import useUserInfoStore from "@/store/user";
import useTransactionStore,{ transaction } from "@/store/pickUp";
import dialBranch from "@/components/dialBranch/index"
const props = defineProps<{
  item: any
  index: number,
}>()
const emit = defineEmits([])

const orderStore = useMyOrderStore()
const userStore = useUserInfoStore()
const transactionStore = useTransactionStore()

console.log(props.item,35768)

//计算代付款金额
const getLeftPrice = (row)=>{
  return row.costList.reduce((sum,item)=>{
    return sum + (parseFloat(item.actualMoney) - parseFloat(item.paidMoney))
  },0)
}

//复制承运单号
const copyCode = (val)=>{
  Taro.setClipboardData({
    data: val
  })
}

//跳转订单详情
const toOrderDetail = async (billNo)=>{
  const res: any = await $post(
      `/selfmachine-system/order/list`,
      {
        billNo
      }
  )
  if(res.data.rows && res.data.rows.length){
    orderStore.orderList = res.data.rows[0]
    Taro.navigateTo({
      url: "/pages/myOrder/order",
    })
  }
  else {
    Taro.showToast({
      icon: 'error',
      title: '未查询到运单'
    })
  }
}

//货物信息转字符串
const goodsInfoString = (item)=>{
  let goods = ""
  item.goodsInfo.forEach((it) => {
    goods =
        goods +
        it.goodsName +
        it.goodsNumber +
        "件," +
        it.weigh +
        "Kg," +
        it.goodsVolume +
        "m³," +
        it.packing +
        ";";
  })
  return goods
}

//网点电话弹窗
const showTelPopup = ref<boolean>(false)
const branchTel = ref<string>('')
const toDial= async (tel) => {
  if(tel){
    branchTel.value = tel
    showTelPopup.value = true
  }
  else{
    Taro.showToast({
      icon: 'none',
      title: '该网点无联系方式'
    })
  }
}
const toMap = (item:any) => {
  Taro.openLocation({
    longitude: Number(item.localX || item.lng),
    latitude: Number( item.localY || item.lat),
    scale: 11
  })
}

</script>

<style lang="scss">
.hpu_item_block {
  width: 100%;
  background-color: #fff;
  border-radius: 16rpx;
  margin-top: 16rpx;
  overflow: hidden;
  padding: 0 24rpx;
  box-sizing: border-box;
  .network {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 104rpx;
    border-bottom: 1px solid #f5f5f5;
    .left,.right {
      display: flex;
      align-items: center;
      image {
        width: 36rpx;
        height: 36rpx;
      }
      text {
        margin-left: 8rpx;
        font-size: 28rpx;
        color: #252525;
        font-weight: 500;
      }
    }
  }
  .codes {
    width: 100%;
    box-sizing: border-box;
    padding-bottom: 24rpx;
    .order {
      width: 100%;
      height: 28rpx;
      margin-top: 24rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 22rpx;
      color: #252525;
      .order_text {
        display: flex;
        align-items: center;
        image {
          width: 18rpx;
          height: 20rpx;
          margin-left: 3rpx;
        }
      }
      .order_detail {
        color: #999;
        font-size: 28rpx;
      }
    }
  }
  .addr {
    width: 100%;
    margin-top: 24rpx;
    display: flex;
    align-items: center;
    font-weight: 500;
    .title_1 {
      width: 40rpx;
      height: 40rpx;
      line-height: 40rpx;
      text-align: center;
      background: linear-gradient(150deg, #3783FF 14%, #125AD2 93%);
      color: #fff;
      font-size: 20rpx;
      border-radius: 8rpx;
    }
    .title_2 {
      width: 40rpx;
      height: 40rpx;
      line-height: 40rpx;
      text-align: center;
      background: linear-gradient(137deg, #13E879 14%, #0EC365 89%);
      color: #fff;
      font-size: 20rpx;
      border-radius: 8rpx;
    }
    .name {
      margin-left: 16rpx;
      font-size: 28rpx;
      color: #252525;
      width: 120rpx;
    }
    .pos {
      margin-left: 24rpx;
      width: calc(100% - 200rpx);
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      color: #252525;
      font-weight: bold;
      font-size: 28px;
    }
  }
  .goods {
    width: 100%;
    border-radius: 8rpx;
    background-color: #f5f5f5;
    margin-top: 24rpx;
    font-size: 24rpx;
    line-height: 32rpx;
    color: #666;
    box-sizing: border-box;
    padding: 24rpx;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
.nut-checkbox__label {
  margin-left: 0;
}
</style>
